home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / h / DLexerBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-10  |  4.8 KB  |  179 lines  |  [TEXT/MPS ]

  1. /* DLGLexerBase.h
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.31
  24.  * Terence Parr
  25.  * Parr Research Corporation
  26.  * with Purdue University and AHPCRC, University of Minnesota
  27.  * 1989-1995
  28.  */
  29.  
  30. #ifndef DLGX_H
  31. #define DLGX_H
  32.  
  33. #include "config.h"
  34. #include ATOKEN_H
  35. #include ATOKENSTREAM_H
  36.  
  37. /* must define what a char looks like; can make this a class too */
  38. typedef char DLGChar;
  39.  
  40. /*  Can have it as a class too: (ack this looks weird; is it right?)
  41. class DLGChar {
  42. private:
  43.     int c;
  44. public:
  45.     DLGChar(int ch) { c = ch; }
  46.     int atom() { return c; }
  47. };
  48. */
  49.  
  50. /* user must subclass this */
  51. class DLGInputStream {
  52. public:
  53.     virtual int nextChar() = 0;
  54. };
  55.  
  56. /* Predefined char stream: Input from FILE */
  57. class DLGFileInput : public DLGInputStream {
  58. private:
  59.     int found_eof;
  60.     FILE *input;
  61. public:
  62.     DLGFileInput(FILE *f) { input = f; found_eof = 0; }
  63.     int nextChar() {
  64.             int c;
  65.             if ( found_eof ) return EOF;
  66.             else {
  67.                 c=getc(input);
  68.                 if ( c==EOF ) found_eof = 1;
  69.                 return c;
  70.             }
  71.         }
  72. };
  73.  
  74. /* Predefined char stream: Input from string */
  75. class DLGStringInput : public DLGInputStream {
  76. private:
  77.     DLGChar *input;
  78.     DLGChar *p;
  79. public:
  80.     DLGStringInput(DLGChar *s) { input = s; p = &input[0];}
  81.     int nextChar()
  82.         {
  83.             if (*p) return (int) *p++;
  84.             else return EOF;
  85.         }
  86. };
  87.  
  88. class DLGState {
  89. public:
  90.     DLGInputStream *input;
  91.     int interactive;
  92.     int track_columns;
  93.     int auto_num;
  94.     int add_erase;
  95.     int lookc;
  96.     int char_full;
  97.     int begcol, endcol;
  98.     int line;
  99.     DLGChar *lextext, *begexpr, *endexpr;
  100.     int bufsize;
  101.     int bufovf;
  102.     DLGChar *nextpos;
  103.     int    class_num;
  104. };
  105.  
  106. /* user must subclass this */
  107. class DLGLexerBase : public ANTLRTokenStream {
  108. public:
  109.     virtual TokenType erraction();
  110.  
  111. protected:
  112.     DLGInputStream *input;
  113.     int interactive;
  114.     int track_columns;
  115.     DLGChar    *_lextext;    /* text of most recently matched token */
  116.     DLGChar    *_begexpr;    /* beginning of last reg expr recogn. */
  117.     DLGChar    *_endexpr;    /* beginning of last reg expr recogn. */
  118.     int    _bufsize;        /* number of characters in lextext */
  119.     int    _begcol;        /* column that first character of token is in*/
  120.     int    _endcol;        /* column that last character of token is in */
  121.     int    _line;            /* line current token is on */
  122.     int    ch;                /* character to determine next state */
  123.     int    bufovf;            /* indicates that buffer too small for text */
  124.     int    charfull;
  125.     DLGChar    *nextpos;    /* points to next available position in lextext*/
  126.     int    cl;
  127.     int automaton;
  128.     int    add_erase;
  129.     DLGChar ebuf[70];
  130.     DLGBasedToken *token_to_fill;
  131.  
  132.     virtual ANTLRAbstractToken *getToken();
  133.  
  134. public:
  135.     virtual void advance(void) = 0;
  136.     void    skip(void);        /* erase lextext, look for antoher token */
  137.     void    more(void);        /* keep lextext, look for another token */
  138.     void    mode(int k);    /* switch to automaton 'k' */
  139.     void    saveState(DLGState *);
  140.     void    restoreState(DLGState *);
  141.     virtual TokenType nextTokenType(void)=0;/* get next token */
  142.     void    replchar(DLGChar c);    /* replace last recognized reg. expr. with
  143.                                      a character */
  144.     void    replstr(DLGChar *s);    /* replace last recognized reg. expr. with
  145.                                      a string */
  146.     int        err_in();
  147.     void    errstd(char *);
  148.  
  149.     int        line()        { return _line; }
  150.     virtual void newline()    { _line++; }
  151.     DLGChar    *lextext()    { return _lextext; }
  152.  
  153.     int        begcol()    { return _begcol; }
  154.     int        endcol()    { return _endcol; }
  155.     void    set_begcol(int a)    { _begcol=a; }
  156.     void    set_endcol(int a)    { _endcol=a; }
  157.     DLGChar    *begexpr()    { return _begexpr; }
  158.     DLGChar    *endexpr()    { return _endexpr; }
  159.     int        bufsize()    { return _bufsize; }
  160.  
  161.     void    setToken(ANTLRTokenBase *t)    { token_to_fill = (DLGBasedToken *)t; }
  162.  
  163.     void    setInputStream(DLGInputStream *);
  164.     DLGLexerBase(DLGInputStream *in,
  165.                  unsigned bufsize=2000,
  166.                  int interactive=0,
  167.                  int track_columns=0);
  168.     virtual ~DLGLexerBase() { delete [] _lextext; }
  169.     void    panic(char *msg);
  170.  
  171.     void    trackColumns() {
  172.                 track_columns = 1;
  173.                 this->_begcol = 0;
  174.                 this->_endcol = 0;
  175.             }
  176. };
  177.  
  178. #endif
  179.